package demo.learnspringboot.Service.lmpi;

import demo.learnspringboot.Service.userService;
import demo.learnspringboot.dto.userDTO;
import demo.learnspringboot.dto.userLoginDTO;
import demo.learnspringboot.entity.User;
import demo.learnspringboot.mapper.booksMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;


@Service
public class userServicelmpi implements userService {

    @Autowired
    private booksMapper booksMapper;


    /*
     **登陆
     ** @param  userDTO
     **
     */
    @Override
    public String Login(userLoginDTO userDTO) {
//        从前端返回的密码和账号
        String name = userDTO.getUsername();
        String passwort = userDTO.getPassword();

//        从数据库读取所有的用户信息
        ArrayList<User> userList;
        userList = booksMapper.login();

//        判断账号是否存在且密码是否正确，返回相应的提示信息
        for (User user : userList) {
            if (user.getUsername().equals(name)) {
                if (user.getPassword().equals(passwort)) {
                    return "登陆成功";
                }
            }
        }
        return "账号或密码错误";
    }
}
